#include "Scroll.h"
#include "Game.h"
#include "ObjectDatabase.h"
#include "Renderer.h"
#include "Util.h"

Scroll::Scroll(ScrollType type) : ScrambledItem(GT_IT_SCROLL, TH_SCROLL_TYPE, g_objectDatabase->getScrambledScrollType(type)) {
	m_types[TH_SCROLL_TYPE] = type;
	const ScrollInfo& info = g_objectDatabase->getScrollInfo(type);
	m_weight = info.weight;
	m_stackable = true;
}

Scroll::Scroll(std::ifstream& file) : ScrambledItem(GT_IT_SCROLL, file) {
	int* tokens = Util::intSplit(file);
	m_types[TH_SCROLL_TYPE] = tokens[0];
	const ScrollInfo& info = g_objectDatabase->getScrollInfo(ScrollType(tokens[0]));
	m_weight = info.weight;
	m_stackable = true;
	load(TH_SCROLL_TYPE, g_objectDatabase->getScrambledScrollType(ScrollType(tokens[0])));
	delete[] tokens;
}

Scroll::~Scroll() {
}

void Scroll::save(std::ofstream& file) const {
	file << getType(TH_GENERIC_TYPE) << "\n";
	ScrambledItem::save(file);
	file << getType(TH_SCROLL_TYPE) << "\n";
}

void Scroll::render(float x, float y) {
	g_renderer->render(*this, x, y);
}

void Scroll::logDetails(TextLog& log) const {
	Item::logDetails(log);
}
